package org.funcking.learn.yl.leetcode;

import junit.framework.TestCase;
import org.funcking.learn.yl.ListNode;

/**
 * 83. 删除排序链表中的重复元素
 * 给定一个排序链表，删除所有重复的元素，使得每个元素只出现一次。
 *
 * 示例 1:
 * 输入: 1->1->2
 * 输出: 1->2
 *
 * 示例 2:
 * 输入: 1->1->2->3->3
 * 输出: 1->2->3
 */
public class ListDeleteDuplicates extends TestCase {
    public ListNode deleteDuplicates(ListNode head) {
        if(head == null) {
            return null;
        }
        
        ListNode pointer = head;
        
        while(pointer.next != null) {
            ListNode next = pointer.next;
            
            if(pointer.val == next.val) {
                ListNode nextNext = next.next;
                pointer.next = nextNext;
            }
            else {
                pointer = pointer.next;
            }
            
        }
        return head;
        
    }
}
